/******************************************************************
 * Copyright (c) 2007 - 2007, Simon Guerard, All rights reserved.
 * 
 * Projet de jeu de course au large.
 * 
 * This File is part of Sail-Race
 * 
 * Sail-Race is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 * 
 * Sail-Race is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with Sail-Race; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
package net.simcafamily.sailrace.spring;

import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * A factory for creating Context objects.
 * 
 * @author $Author: simon.guerard $
 * @version $Revision: 403 $
 */
public class ContextFactory {

    /** The Constant LOGGER. */
    private static final Log log = LogFactory.getLog(ContextFactory.class);

    /** The hcontext. */
    private static HashMap<String, ApplicationContext> hcontext = new HashMap<String, ApplicationContext>();

    /**
     * Permet de creer le contexte Spring. Object en singleton
     * 
     * @param pathAppCtx
     *            the path app ctx
     * 
     * @return le contexte Spring
     */
    public static ApplicationContext getContext() {
        final String pathAppCtx = "applicationContext.xml";
        ApplicationContext context = ContextFactory.hcontext.get(pathAppCtx);
        if (context == null) {
            ContextFactory.log.info("Fichier Spring de context utilise : " + pathAppCtx);
            context = new ClassPathXmlApplicationContext(pathAppCtx);
            ContextFactory.hcontext.put(pathAppCtx, context);
        }
        return context;
    }
}
